<template>
    <a-spin :spinning="spinning">
      <a-row :gutter="10">
        <a-col :span="24">
          <a-card class="requiredFormItem">
            <title-name title="基本信息" />
            <custom-form
              ref="formBase"
              :editModel="''"
              :is-validate="true"
              :form="form"
              :form-list="formOption"
            ></custom-form>
          </a-card>
        </a-col>
        <a-col :span="24">
          <component
            :key="componentName"
            :is="componentName"
            ref="component"
            :base-form-info="form"
            :spinning.sync="spinning"
            @setPerProjectAddress="setPerProjectAddress"
          ></component>
        </a-col>
      </a-row>
    </a-spin>
</template>
<script>
const allComponents = require.context('./../../../../../views/project/projectManagementPlanning/projectManagementPlanningComponents/components', false, /.*\.vue$/)
import { pageName } from './../../../../../views/project/projectManagementPlanning/projectManagementPlanningComponents/components/model.js'
import { getPlanTaskBaseInfo } from '@/api/projectManagementPlanning/projectPlanningTaskList'
import mixins from './mixins'
let res_components = {}
allComponents.keys().forEach((fileName) => {
  let comp = allComponents(fileName)
  res_components[fileName.replace(/^\.\/(.*)\.\w+$/, '$1')] = comp.default
})
export default {
  name: 'projectManagementPlanningComponents',
    mixins: [mixins],
  data() {
    return {
       spinning: false,
       form: {},
       businessTypeCode:null,
      formOption: [
        {
          label: '项目名称',
          keyName: 'projectName',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '项目编号',
          keyName: 'projectCode',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '策划项目',
          keyName: 'planProject',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '责任部门/责任人',
          keyName: 'duty',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '完成期限',
          keyName: 'deadline',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '操作人',
          keyName: 'projectOperatorName',
          type: 'BaseInput',
          disabled: true
        },
        {
          label: '创建时间',
          keyName: 'createTime',
          type: 'BaseInput',
          disabled: true
        }
      ],
      rules: {},
      pageType: ''
    }},
  components: res_components,

  computed: {
      componentName(){
          return pageName[this.businessTypeCode-1]
      }
  },

  created() {
   this.getPlanTaskBaseInfo()
   let businessTypeCode = this.$route.query.businessType.substring(3,5);
   this.businessTypeCode = businessTypeCode?businessTypeCode*1:null;
//    const detailUrl = decodeURIComponent(this.$route.query.detailUrl)
//    const detailUrlArr = detailUrl.slice(detailUrl.indexOf('?')+1).split('&amp;amp;')
   this.$route.query.editModel = '0'
   this.$route.query.pageType = 'detail'
  },

  mounted() {

  },

  methods: {
        setPerProjectAddress(data) {
      if (data) {
        this.form.projectAddress = data
      }
    },
      getPlanTaskBaseInfo() {
      const { id} = this.$route.query
      const query = {
        planTaskDetailId: id
      }
    query.latestData = true
      this.spinning = true
      getPlanTaskBaseInfo(query)
        .then((res) => {
          this.spinning = false
          this.form = res.data
        })
        .catch(() => {
          this.spinning = false
        })
    },
  }
}
</script>
